package file.in.out.stream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileOutStream {
	public static void main(String [] args) throws IOException{
		FileOutputStream fout;
		FileInputStream fin;
		int i;
		try{
			//open input file
			try{
				fin = new FileInputStream("F:\\test.txt");
			}
			catch(FileNotFoundException e){
				System.out.println("Input File Not Found");
				return;
			}
			
			//open output file
			try{
				fout = new FileOutputStream("F:\\source.txt");
			}
			catch(FileNotFoundException e){
				System.out.println("Error Open Output File");
				extracted();
				return;
			}
		}
		catch(ArrayIndexOutOfBoundsException e){
			System.out.println("Usage: CopyFile from To");
			extracted();
			return;
		}
		
		//copy file
		try{
			do{
				i = fin.read();
				if(i!=-1) fout.write(i);
			}while(i!=-1);
		}
		catch(IOException e){
			System.out.println("File Error");
		}
		fin.close();
		fout.close();
	}

	private static void extracted() {
		return;
	}
}
